#pragma once

#include "TrManager.h"
#include "TrTypes.h"
#include "CTP/ThostFtdcTraderApi.h"

#ifndef BUILD_STATIC
# if defined(TRLOADER_LIB)
#  define TRLOADER_EXPORT __declspec(dllexport)
# else
#  define TRLOADER_EXPORT __declspec(dllimport)
# endif
#else
# define TRLOADER_EXPORT
#endif

typedef CThostFtdcTraderApi* (*CTPCreator)(const char*);

class TRLOADER_EXPORT TrLoader : public CThostFtdcTraderSpi
{
public:
    TrLoader(const TrConf_CTP& ctp, const TrConf_Log& log);
    ~TrLoader();
    void release();
    void ReqUserLogin();
    void ReqQryInstrument();
    bool IsErrorRspInfo(CThostFtdcRspInfoField* pRspInfo);
    ///////////////////////////////////////////////////
    virtual void OnFrontConnected();
    virtual void OnFrontDisconnected(int nReason);
    virtual void OnRspAuthenticate(CThostFtdcRspAuthenticateField* pRspAuthenticateField, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast);
    virtual void OnRspUserLogin(CThostFtdcRspUserLoginField* pRspUserLogin, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast);
    virtual void OnRspQryInstrument(CThostFtdcInstrumentField* pInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast);
    virtual void OnRspError(CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast);
};
